package pct.post;

import java.util.LinkedList;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import pct.database.PcServiceImpl;
import pct.entity.Post;
import pct.manage.StatusManager;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

public class PostSA  extends ActionSupport implements SessionAware, Preparable {
	private int postID;
	private String type;
	private int topicID;
	private String userID;
	
	private Map<String, Object> session;
	private PcServiceImpl pcService = new PcServiceImpl();
	public String execute(){
		StatusManager sm=(StatusManager) session.get("status");
		LinkedList<Post> relatedPosts = sm.getRelatedPosts();
		pcService.addPostSA(type, postID,userID);
		sm.setRelatedPosts(pcService.getRelatedPosts(topicID));
		session.put("status",sm);
		return SUCCESS;
	}
	
	public String getType()
	{
		return type;
	}
	public void setType(String type)
	{
		this.type=type;
	}
	public String getUserID() {
		return userID;
	}

	public void setUserID(String userID) {
		this.userID = userID;
	}

	public int getTopicID() {
		return topicID;
	}

	public void setTopicID(int topicID) {
		this.topicID = topicID;
	}

	@Override
	public void prepare() throws Exception {
		pcService.connectDB();
		
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		this.session = arg0;
		
	}
	public int getPostID() {
		return postID;
	}

	public void setPostID(int postID) {
		this.postID = postID;
	}

}
